package dataview;

import java.util.LinkedList;
import org.jdom.Element;
import store.Termine;

public class Termini extends LinkedList<Termine> {
	private static final long serialVersionUID = -3619118165786653602L;
	
	public Termini getTerminiDiTipo(TipoTermine tipo) {
		Termini termini = new Termini();
		for (Termine termine : this)
			if (termine.getTipo() == tipo) termini.add(termine);
		return termini;
	}
	
	public Element getElementTerminiDiTipo(TipoTermine tipo, boolean multiplo) {
		Element element = new Element(tipo.name());
		Termini termini = getTerminiDiTipo(tipo);
		if (!multiplo) {
			if (termini.size() >= 1) 
//				element.setText(termini.getFirst().getTermine());
				element.setAttribute("nome", termini.getFirst().getTermine());
		} else for (Termine termine : termini)
			element.addContent(termine.toXml());
		return element;
	}
	
	@Override
	public String toString() {
		String s = super.toString();
		return s.substring(1, s.length()-1);
	}
}
